import Vue from 'vue'
import App from './App.vue'
import './registerServiceWorker'
import router from './router/index'
import store from './store'
import * as api from './request/api/api.js'

import {
  Message
} from 'ant-design-vue'

import 'lib-flexible'

Vue.config.productionTip = false

Vue.prototype.$api = api
Vue.prototype.$message = Message


new Vue({
  router,
  store,
  render: h => h(App),
  mounted () {
    document.dispatchEvent(new Event('render-event'))
  }
}).$mount('#app')

// 全局路由守卫
router.beforeEach((to, from, next) => {
  // 设置title
  if(to.meta.title){
    document.title = to.meta.title
  }
  if(to.meta.requireAuth){
    if(store.getters.is_login){
      next()
    }else{
      next({path: '/login'})
    }
  }else{
    next()
  }
})
